#ifndef JBK_IA_GA_TOURNAMENT_SELECTION_H
#define JBK_IA_GA_TOURNAMENT_SELECTION_H

#include "GeneticAlgorithm.h"

namespace GA {
class TournamentSelectionGA : public GeneticAlgorithm {
public:
	/* ctor */
	TournamentSelectionGA(int nPopulation, Individual* const* initialPopulation);

	/* dtor */
	~TournamentSelectionGA();

	/* evolve one step */
	void evolveOneStep();

	/* elitism */
	void setUseElitism(bool flag);

	/* bests */
	const Individual& getBestIndividualCurrent() const;
	const Individual& getBestIndividualEver() const;

private:
	int          _nPopulation; /* population size */
	Individual** _population;  /* population      */

	bool _useElitism;          /* elitism flag    */

	Individual* _bestIndividualCurrent; /* best current */
	Individual* _bestIndividualEver;    /* best ever    */

	void _placeBestIndividualFirst(); /* place best first    */
	void _evaluatePopulation();       /* evaluate population */
	Individual* _pickParent();        /* get a fit parent    */
};
} // GA

#endif // JBK_IA_GA_TOURNAMENT_SELECTION_H

